package model.algorithms.splitting;


public class RecursiveRandomPermutations extends SplittingAlgorithm
{
	public RecursiveRandomPermutations( String name )
	{
		super( name );
	}
	
	@Override
	protected int[] bestNodesMapping()
	{
		int requestNodesNumber = this.getVirtualNetwork().getNodes().size();
		int substrateNetworksNumber = this.getSdnNetworks().size();
		int nodesMapping[] = new int[ requestNodesNumber ];
		
		int bestNodesMapping[] = new int[ requestNodesNumber ];
		double bestNetworkMappingCost = Integer.MAX_VALUE;
		int maxExperimentsNumber = 5;
		
		int trialsNumber = 10 * substrateNetworksNumber * requestNodesNumber;
		
		for( int i = 0; i < maxExperimentsNumber; i++ )
		{
			for( int j = 0; j < requestNodesNumber; j++ )
				nodesMapping[ j ] = ( int )( Math.random() * substrateNetworksNumber );
			
			nodesMapping = this.nodesMapping( nodesMapping, trialsNumber );
			
			double networkMappingCost = this.networkMappingCost( nodesMapping );
			
			if( networkMappingCost < bestNetworkMappingCost )
			{
				bestNetworkMappingCost = networkMappingCost;
				
				bestNodesMapping = nodesMapping.clone();
				//for( int k = 0; k < requestNodesNumber; k++ )
					//bestNodesMapping[ k ] = nodesMapping[ k ];
			}
		}
		
		return bestNodesMapping;
	}
	
}
